<?php
require DT_CORE.'/buyhelp/common.inc.php';
defined('IN_IXDCW') or exit('Access Denied');
$navname ='buy';
$MOD['name']='买车助手_二手车';

$tableC     = Table::name(Table::NAME_AUTO_CATEGORY);
$tableRC    = Table::name(Table::NAME_AUTO_RANK_CAR);
$tableM     = Table::name(Table::NAME_AUTO_MODEL);
$table      = $db->getPre().'buy';
$LEVEL      = AutoCategory::getCache(AutoCategory::TYPE_LEVEL);


/*乘用 商用 房车 新能源 类别数组*/
$RANK = Pcache::read('category-'.$moduleid.'.php');
$i = 1;
foreach($RANK as $key => $val) {
	if($val['parentid'] == 4960) {
		$arrCategory[$i]['catid']         = $val['catid'];
		$arrCategory[$i]['catname']       = $val['catname'];
		$arrCategory[$i]['arrchildid']    = $val['arrchildid'];
		$i++;
	}
}

/*二手车 筛选项*/
$TYPES = explode('|', $MOD['type']);
if (!empty($ARE)) {
	$mainarea=Xd_get_arealists($ARE);
} else {
	$mainarea[0] = get_mainarea(0);
}


// normal
$filter['typeid'] = getgpc('typeid');
$filter['areaid'] = getgpc('areaid');



/*Sql 筛选条件*/
$condition = "(status=3 or status=2)";
if ($filter['typeid'] && array_key_exists($filter['typeid'], $TYPES)) {
	$condition .= " AND typeid={$filter['typeid']} ";
}

/*乘用 商用 类别*/
if ($cartypeid)         $condition .= " AND catid in (".$arrCategory[$cartypeid]['catid'].") ";
if ($areaid) 	        $condition .=  $ARE['child'] ? " AND areaid IN (".$ARE['arrchildid'].") " : " AND areaid=$areaid ";


$total    = $db->count($table, $condition, $DT['cache_search']);
$do       = new BuyModule($moduleid);
if ($total) {
	$tags = $do->getList($condition,$city_order.$ORDER[$order],($DT['cache_search'] && $page == 1) ? 'CACHE' : '', $DT['cache_search']);
	if ($page == 1 && $kw) keyword($kw, $items, $moduleid);
}



include template('buyList','buyhelp');
